package org.crumbleworks.crumbchat.server;

import org.crumbleworks.crumbchat.server.controller.ServerControllerInterface;

public class InputParser {
    private final String BIND_COMMAND = "bind";
    private final String UNBIND_COMMAND = "unbind";
    private final String SHUTDOWN_COMMAND = "quit";

    private ServerControllerInterface controller;

    public InputParser(ServerControllerInterface controller) {
        this.controller = controller;
    }

    public void parseInput(String input) {
        if (input.startsWith("/")) {
            input = input.substring(1);
            String[] splittedInput = input.split(" ");
            String command = splittedInput[0];

            if (command.equals(BIND_COMMAND)) {
                // controller.bindPorts(Integer.parseInt(splittedInput[1]), Integer.parseInt(splittedInput[2]));
            }
            else if (command.equals(UNBIND_COMMAND)) {
                controller.unbindPorts(false);
            }
            else if (command.equals(SHUTDOWN_COMMAND)) {
                controller.unbindPorts(true);
            }
        }
        else {
            controller.sendMessageToClients(input);
            System.out.println("blarght");
        }
    }
}
